package b2.widget
{
	import com.greensock.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.utils.*;

	public class Label extends Sprite
	{
		private var tf:TextField;
		private var timer:Timer;
		private var biggerFlag:Boolean;
		
		private var oldPosX:Number;
		private var oldPosY:Number;
		private var oldWidth:Number;
		private var oldHeight:Number;
		
		public function Label(text:String, color:int = 0xFFFFFF, bold:Boolean = true)
		{
			super();
			tf = new TextField();
			tf.selectable = false;
        	tf.autoSize = TextFieldAutoSize.LEFT;
			tf.defaultTextFormat = new TextFormat("微软雅黑", 12, color, bold);
			tf.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			tf.text = text;
			addChild(tf);
			timer = new Timer(300);
			timer.addEventListener(TimerEvent.TIMER, onTick);
		}
		
		//开始闪烁
		public function set blink(flag:Boolean):void
		{
			if (flag)
			{
				oldPosX = this.x;
				oldPosY = this.y;
				oldWidth = this.width;
				oldHeight = this.height;
				timer.start();
			}
			else
			{
				timer.stop();
			}
		}
		
		private function onTick(event:Event):void
		{
			if (this.parent == null)
			{
				timer.stop();
			}
			else
			{
				if (biggerFlag)
				{
					var scale:Number = 0.8;
					this.x = oldPosX - (scale - 1) * oldWidth / 2;
					this.y = oldPosY - (scale - 1) * oldHeight / 2;
					this.scaleX = scale;
					this.scaleY = scale;
//					tf.filters = [new GlowFilter(0x000000, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
				}
				else
				{
					this.x = oldPosX;
					this.y = oldPosY;
					this.scaleX = 1;
					this.scaleY = 1;
//					tf.filters = [new GlowFilter(0xFFFF00, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
				}
				biggerFlag = !biggerFlag;
			}
		}
	}
}